Adding problems from Colombian Programming Contest 2011. Only F is missing!
[andmenj-acm.git] / 12318 - Digital Roulette / 12318.cpp
blobf38293c7d68376ae4d2830d426d0c8a4c0997d5e
1 // Equipo Poncho, Carriel y Ruana
2 // Accepted on UVa
3 using namespace std;
4 #include <algorithm>
5 #include <iostream>
6 #include <iterator>
7 #include <sstream>
8 #include <fstream>
9 #include <cassert>
10 #include <climits>
11 #include <cstdlib>
12 #include <cstring>
13 #include <string>
14 #include <cstdio>
15 #include <vector>
16 #include <cmath>
17 #include <queue>
18 #include <stack>
19 #include <list>
20 #include <map>
21 #include <set>
23 template <class T> string toStr(const T &x)
24 { stringstream s; s << x; return s.str(); }
25 template <class T> int toInt(const T &x)
26 { stringstream s; s << x; int r; s >> r; return r; }
28 #define For(i, a, b) for (int i=(a); i<(b); ++i)
29 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
30 #define D(x) cout << #x " = " << (x) << endl;
32 const double EPS = 1e-9;
34 int cmp(double x, double y = 0, double tol = EPS) {
35 return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
38 int main(){
39 int n, m;
40 while (cin >> n >> m) {
41 if (n == 0 and m == 0) break;
42 int k; cin >> k;
43 vector<long long> grad(k + 1);
44 for (int i = 0; i < k + 1; ++i) {
45 cin >> grad[i];
47 long long mod = n + 1;
48 //assert(grad.size() == k + 1);
49 set<long long> ans;
50 for (long long x = 0; x <= m; x++){
51 long long y = 0;
52 long long d = 1;
53 for (int i = 0; i < grad.size(); ++i) {
54 //printf(" y = y + %d\n", grad[i] * d);
55 y += ((grad[i] % mod) * d) % mod;
56 y %= mod;
57 d = (d * (x % mod)) % mod;
59 ans.insert(y % mod);
60 //printf("added %d\n", y % mod);
62 cout << ans.size() << endl;
64 return 0;